<!-- 兰文杰 currentDate-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div class="modal fade" id="uploadFileModal" data-backdrop="static"
	tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel"
	aria-hidden="true">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="staticBackdropLabel">上传文件</h5>
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<div class="modal-body">
				<form id="fileForm" method="post" enctype="multipart/form-data">
					<div class="form-group">
						<label for="upload-file" class="col-form-label">请选择上传的文件：</label>
						<input type="file" class="form-control" id="upload-file"
							name="files" required aria-describedby="upload-file">
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" onclick="upload()">上传</button>
				<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script>
	function upload() {
		var fileDom = $("#upload-file")[0];
		var files = fileDom.files;
		if (files.length == 0) {
			alert("请先选择要上传的文件！");
			return;
		}
		var formData = new FormData();
		formData.append("files", files[0]);
		$.ajax({
			url : "${pageContext.request.contextPath}/upload/file",
			type : "POST",
			data : formData,
			dataType : "json",
			cache: false,
            processData: false,
            contentType: false,
			success : function(result) {
				if (result.code === 0) {
					alert(result.message);
					$("#uploadFileModal").modal("hide");
				} else {
					alert(result.message);
				}
				//$("#folder-name").val("");
			},
			error : function(err) {
				alert("！");
				console.log(err);
			}
		});
	}
</script>